package com.example.perplonews.a_d_fragment.d_live

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.Utils
import com.example.perplonews.R
import com.example.perplonews.a_b_utils.LjlUtils
import com.tencent.live2.V2TXLivePlayer
import com.tencent.live2.impl.V2TXLivePlayerImpl
import com.tencent.rtmp.ui.TXCloudVideoView


class Live_detailsActivity : AppCompatActivity() {
    private val videoView: TXCloudVideoView by lazy { findViewById<TXCloudVideoView>(R.id.video_view) }
    val mLivePlayer: V2TXLivePlayer = V2TXLivePlayerImpl(Utils.getApp())
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_live_details)
        init()
        start()


    }

    private fun init() {

        mLivePlayer.setRenderView(videoView)


    }

    private fun start() {

        var toInt = intent.getStringExtra("postion")?.toInt()
        LjlUtils.Ljl_Loge("------"+toInt)
        when (toInt) {
            0 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv1"
                mLivePlayer.startPlay(flvUrl)
            }
            1 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv2"
                mLivePlayer.startPlay(flvUrl)
            }
            2 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv3"
                mLivePlayer.startPlay(flvUrl)
            }
            3 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv4"
                mLivePlayer.startPlay(flvUrl)
            }
            4 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv5"
                mLivePlayer.startPlay(flvUrl)
            }
            5 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv14"
                mLivePlayer.startPlay(flvUrl)
            }
            6 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv15"
                mLivePlayer.startPlay(flvUrl)
            }
            7 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv13"
                mLivePlayer.startPlay(flvUrl)
            }
            8 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv6"
                mLivePlayer.startPlay(flvUrl)
            }
            9 -> {
                val flvUrl = "rtmp://58.200.131.2:1935/livetv/cctv8"
                mLivePlayer.startPlay(flvUrl)
            }
        }
    }

    override fun onPause() {
        super.onPause()
        mLivePlayer.stopPlay()
    }

    override fun onStop() {
        super.onStop()
        mLivePlayer.stopPlay()
    }
}